let app = getApp();
Page({
  data: {
    chargingList: [],    
    chargingLoading: true,
    chargingError: '',
    consultantId: 0
  },

  onLoad(options) {
    this.setData({
      consultantId: options.consultantId ,
      url: app.globalData.url 
    });

    if (this.data.url.slice(-1) !== '/') {
      this.setData({ url: this.data.url + '/' });
    }

    this.getChargingStandards();
  },

  getChargingStandards() {
    this.setData({ chargingLoading: true, chargingError: '' });

    wx.request({
      url: this.data.url+'chargingStandards/consultant/'+this.data.consultantId,
      method: 'GET',
      success: (res) => {
        this.setData({ chargingLoading: false });
        if (res.data && res.data.code === 200) {
          this.setData({ chargingList: res.data.data  });
        } else {
          this.setData({ chargingError: res.data?.msg || '获取收费标准失败' });
        }
      },
      fail: (err) => {
        this.setData({ 
          chargingLoading: false, 
          chargingError: '网络请求失败，请稍后重试' 
        });
        console.error('加载全部收费标准失败：', err);
      }
    });
  }
});